﻿using System.Windows;
using Baosight.Platform.Core.UI.Controls;
using System.Collections.Generic;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCommon;
using System.Windows.Threading;
using System;
using System.Windows.Controls;
using Baosight.ZNH.ZMCommon.ChildWindows;

namespace Baosight.ZNH.ZMCS.UI.ChildWindows
{
    /// <summary>
    /// 系统模块的新增、修改、查看页面
    /// 对应后台ServiceZMCS02.java
    /// @author 严洪浩
    /// </summary>
    public partial class SystemModule : EFViewCmes
    {

        public SystemModule(string dialogType)
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
            Init(dialogType);
        }

        /// <summary>
        /// 初始化父类EFViewCmesProperty的值，每次点击“确定”、“返回”时执行此方法，从新赋值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.spWindows.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 初始化页面数据
        /// </summary>
        private void Init(string type)
        {
            type = type == null ? "insert" : type.ToLower();

            switch (type)
            {
                case "insert":
                    this.fdNature.Value = "标准版";
                    this.fdStatus.Value = "在用";
                    this.fdType.Value = "业务";
                    base.Mode = OperationMode.Insert;
                    break;
                case "update":
                    base.Mode = OperationMode.Update;
                    this.fdModuleNo.IsReadOnly = true;
                    break;
                case "detail":
                    this.Commit.Visibility = Visibility.Collapsed;
                    BaseTools.EFDataFieldNotEnabled(this.spWindows.GetChildObjects<EFDataField>(null, true));
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            base.OnCommitButtonClick("ZMCS02", sender, e);
        }

        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            CmesWindows _window = this.Parent as CmesWindows;
            _window.DialogResult = false;
            _window.Close();
        }

        #region 公用方法
        /// <summary>
        /// 根据 moduleLevel的值，返回fdModuleLevelName的值
        /// </summary>
        /// <param name="moduleLevel"></param>
        /// <returns></returns>
        public void SetModuleLevelName(string moduleLevel)
        {
            if (null == moduleLevel)
            {
                this.fdModuleLevelName.Value = "系统模块";
            }
            switch (moduleLevel)
            {
                case "0":
                    this.fdModuleLevelName.Value = "系统模块";
                    break;
                case "1":
                    this.fdModuleLevelName.Value = "一级模块";
                    break;
                case "2":
                    this.fdModuleLevelName.Value = "二级模块";
                    break;
                case "3":
                    this.fdModuleLevelName.Value = "三级模块";
                    break;
                default:
                    this.fdModuleLevelName.Value = "系统模块";
                    break;
            }
        }
        #endregion
    }
}

